﻿#if _MSC_VER >= 1600
#pragma execution_character_set("UTF-8")
#endif

#include "widget.h"
#include <QMultimedia>
#include<QTabWidget>
#include<QVideoWidget>
#include<QMediaPlaylist>
#include<QHBoxLayout>
#include<QDebug>
#include<QGridLayout>
#include<iostream>
#include<QMimeData>
#include<QFile>
#include<QFileInfo>
#include<QTextStream>
#include<QStringList>
#include<vector>
#include<QStatusBar>
#include<QThread>
#include<QStandardItem>
#include<QFileDialog>
#include<QMessageBox>
#include<QMediaMetaData>
#include<QImage>
#include<array>


namespace xingcent_player{

const QString str_list_tips="播放列表";
const QString str_text_place_hole="歌曲名 - 歌手";
const QString str_pre="";
const QString str_pause = "";
const QString str_next="";
const QString str_bar="";
const QString str_dial="";
const QString str_list_icon=":img/music.png";


const QString getList(){
    return str_list_tips;
}

static QString formatTime(qint64 timeMilliSeconds)
{
    qint64 seconds = timeMilliSeconds / 1000;
    const qint64 minutes = seconds / 60;
    seconds -= minutes * 60;
    return QStringLiteral("%1:%2")
            .arg(minutes, 2, 10, QLatin1Char('0'))
            .arg(seconds, 2, 10, QLatin1Char('0'));
}



// 其实 基类的成员不应该在这里搞事情的。。。这里我违背以下
Widget::Widget(XingcentPlayerUi *parent)
    : XingcentPlayerUi(parent)

{

    setAcceptDrops(true);                 // ���� �����϶��ļ�
    //  initialStatusBar();
    std::vector<QString>list = readList("./data.txt");            // ��ȡ�����б�

    ;
    m_bar.setRange(0, 100);                  //���ý������ķ�Χ
    m_bar.setPageStep(1);
    //
    auto hHead = new QStandardItemModel(this);
    // hHead->setHorizontalHeaderItem();

    auto myItem = new QStandardItem(str_list_tips);
    myItem->setTextAlignment(Qt::AlignLeft);
    QIcon icon(str_list_icon);
    myItem->setIcon(icon);
    hHead->setHorizontalHeaderItem(0, myItem);

    m_view.setModel(hHead);
    m_view.setColumnWidth(0,400);
    m_view.setMaximumWidth(400);
    //m_view .setShowGrid(false);             //����ʾ����

    m_view.setEditTriggers(QAbstractItemView::NoEditTriggers);

    m_dial.setRange(0, 100);                 // ���������ķ�Χ
    m_dial.setToolTip("vol");              //����toolTip
    m_dial.setVisible(true);                //��ֻΪ�ɼ�
    m_dial.setValue(30);                   // ����Ĭ�ϵ�����


    m_pre.setToolTip(str_pre);
    m_pre.setStyleSheet("border-radius:30px;background-color:white;border-image:url(:img/m_pre.png);");


    m_pause.setToolTip(str_pause);
    m_pause.setStyleSheet("border-radius:30px;background-color:white;border-image:url(:img/m_pause.png);");


    m_next.setToolTip(str_next);
    m_next.setStyleSheet("border-radius:30px;background-color:white;border-image:url(:img/m_next.png);");


    m_bar.setToolTip("position");

    m_search.setStyleSheet("border-radius:10px;border-image:url(:img/m_search.png);");


    m_text.setPlaceholderText(str_text_place_hole);


    //  m_volup.setStyleSheet("border-image:url(:img/m_volup.ico)");
    //  m_voldown.setStyleSheet("border-image:url(:img/m_voldown.ico)");

    auto  playlist = new QMediaPlaylist(this);
    //���ò����б��Ĳ��ŷ�ʽ������һ��Ҫ���÷�������һ���ͻ��ص� -1
    playlist->setPlaybackMode(QMediaPlaylist::Loop);
    // playlist->addMedia(QUrl("E:/XINGCENT/2.mp4"));
    qDebug() << "list .size () = " << list.size();
    for (auto i = 0; i < list.size(); ++i)
    {
        playlist->addMedia(QUrl(list[i]));
        qDebug() << "path" << list[i];
    }
    qDebug() << playlist;
    playlist->setCurrentIndex(0);

    //    m_pre.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_text.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_search.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_pause.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_next.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_bar.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_videoPlay.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //    m_dial.setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);

    m_player->setPlaylist(playlist);
    //auto   videoWidget = new QVideoWidget(this);






    m_videoPlay.show();

    m_player->setVideoOutput(&m_videoPlay);


    setLayoutDirection(Qt::LeftToRight);

    setConnect();



    updateList("./data.txt");
    //playlist->setCurrentIndex(0);
    // m_player->play();

    std::cout << " hello World " << __LINE__ << std::endl;


}

Widget::~Widget()
{

}


void Widget::onPre()
{
    auto list = m_player->playlist();
    int index = list->currentIndex(); // ��ȡ��ǰ�������ֵ��±�

    index = (--index + list->mediaCount()) % list->mediaCount();
    list->setCurrentIndex(index);

    //qDebug() << "file" << list->media(index).canonicalUrl().fileName();

    m_videoPlay.setToolTip(getBaseName(list->media(index).canonicalUrl().path()));   //���õ�ǰ���ŵ�toolTip

    m_player->play();
    checkToDisplay();
    changeMnowTitle();
    setViewCurrentIndex(index);


}

void Widget::onPause()
{
    auto state = m_player->state();
    if (QMediaPlayer::PausedState == state)
    {
        m_player->play();

        m_pause.setStyleSheet("border-radius:30px;background-color:white;border-image:url(:img/m_play.png);");
    }
    else if (QMediaPlayer::PlayingState == state)
    {
        m_player->pause();

        m_pause.setStyleSheet("border-radius:30px;background-color:white;border-image:url(:img/m_pause.png);");

    }
    auto list = m_player->playlist();             // ��ȡ�����б�
    auto index = list->currentIndex();          // ��ȡ ��ǰ�Ĳ�����Ŀ
    m_videoPlay.setToolTip(getBaseName(list->media(index).canonicalUrl().path()));   //���õ�ǰ���ŵ�toolTip


}

void Widget::onNext()
{
    auto list = m_player->playlist();
    int index = list->currentIndex();             // ��ȡ��ǰ�������ֵ��±�
    //���»�ȡ�±�
    index = (++index + list->mediaCount()) % list->mediaCount();
    list->setCurrentIndex(index);                 //���ñ��β��ŵ��±�Դ

    m_videoPlay.setToolTip(getBaseName(list->media(index).canonicalUrl().path()));   //���õ�ǰ���ŵ�toolTip
    m_player->play();

    checkToDisplay();
    changeMnowTitle();
    setViewCurrentIndex(index);


}

void Widget::onValChange(int vol)
{
    qDebug() << "volChange";
    m_player->setVolume(vol);
    m_dial.setToolTip(QString::number(vol));
    if (vol >= 90)
    {
        m_dial.setToolTip(QString("����������������"));
        std::cout << "����������������" << std::endl;
    }
}

void Widget::onPositionChange(qint64 num)
{
    auto dura = m_player->duration();      //��ȡ�ܵ�ʱ��
    m_bar.setRange(0, dura);               //����ֵ�ķ�Χ
    m_bar.setValue(num);                 // ���õ�ǰ��ֵ
    auto currentTime = num;               //  ��ȡ��ǰ��ֵ
    auto current_text = formatTime(currentTime); // ����ǰ���ǽ�ת��Ϊ 00��00 �֣���
    auto totalTime = formatTime(dura);           //���ܵ�ʱ��תΪ 00��00 ��:��
    QString str = current_text + " - " + totalTime; //��ʱ��תΪQString
    m_time.setText(str);                  // ���±�ǩ��ֵ


}

void Widget::onBarPositionChange(int num)
{

    auto currentValue = m_bar.value();
    // qDebug()<<__FUNCSIG__<<currentValue;

    if ((m_player->position() - currentValue) > 99 || currentValue - m_player->position() > 99)
    {
        m_player->setPosition(num);
    }
    ;

}

int Widget::onBarChange()
{
    int ret = 0;
    ret = m_bar.value();

    return ret;
}

void Widget::onAutoNext()
{
    auto list = m_player->playlist();

    int index = list->currentIndex();             // ��ȡ��ǰ�������ֵ��±�

    qDebug() << __LINE__ << list;
    qDebug() << "index = " << index << " list -> cout = " << list->mediaCount();
    m_videoPlay.setToolTip(getBaseName(list->media(index).canonicalUrl().path()));   //���õ�ǰ���ŵ�toolTip
    m_player->play();
    qDebug() << "file __LINE__ " << __LINE__ << list->media(index).canonicalUrl().fileName();
    checkToDisplay();
    changeMnowTitle();
    setViewCurrentIndex(index);


}

void Widget::setPosition(int position)
{
    if ((position - m_player->position() > 99) | (m_player->position() - position > 99))
    {
        // qDebug()<<__LINE__<<__FUNCSIG__;

        m_player->setPosition(position);
    }

}

void Widget::setIndex(int index)
{
    //  qDebug()<<__LINE__<<" <<< -- line  , call   "<<__FUNCSIG__;
    auto list = m_player->playlist();
    list->setCurrentIndex(index - 1);
    m_player->play();
}

void Widget::searchM()
{
    QString str = m_text.text();
    int index = containFile("./data.txt", str);
    if (-1 != index)
    {
        auto list = m_player->playlist();
        list->setCurrentIndex(index);
        m_player->play();
        m_text.clear();
    }


}

void Widget::openFileDialog()
{

    QFileDialog fg(this);
    fg.setAcceptMode(QFileDialog::AcceptOpen);
    if (fg.exec() == QFileDialog::Accepted)
    {
        QString path = fg.selectedFiles()[0];
        qDebug() << " line " << __LINE__ << "  , path " << path;
        auto list = m_player->playlist();
        qDebug() << __LINE__ << "<< line  >> list = " << list;
        list->addMedia(QUrl(path));
        qDebug() << "list -> mediaCount() = " << list->mediaCount();
        list->setCurrentIndex(list->mediaCount() - 1);
        m_player->play();
    }

}

void Widget::onDoubleClickTheContent(const QModelIndex &index)
{
    auto mod= m_view.currentIndex();
    if(mod == index)
    {
        qDebug()<<" I get it ";
        qDebug()<<mod.data();

        auto list = m_player->playlist();
        int c_cx= list->mediaCount();

        for( int i = 0 ; i< c_cx;++i)
        {
            auto u_con=list->media(i);
            auto mNa= u_con.canonicalUrl().fileName();

            auto name=u_con.canonicalResource().url().toLocalFile();
            qDebug()<< " ���� ���ֲ��ң� "<< name<<"    ---  "<<mNa;


            if(mNa.contains(QString(mod.data().toString())) | mod.data().toString().contains(mNa))
            {
                qDebug()<<" ���ҵ���     >>>>>>>>>>>>>>>>>>>: "<<mNa;
                list->setCurrentIndex(i);
                m_player->play();
                return ;
            }
        }
    }

}

void Widget::onSizeChange()
{

}

void Widget::changeImage(QMediaPlayer::MediaStatus status)
{
    qDebug()<<"call changeImage"<<status;
    if(status == QMediaPlayer::BufferedMedia)
    {
        auto author = m_player->metaData("Author");
        auto title =m_player->metaData("Title");
        qDebug()<<"author "<<author<<" , Title : "<<title;
        auto dura =m_player->metaData("Duration").toString();
        qDebug()<<"dura "<<(dura);
        auto image = m_player->metaData("CoverArtImage");
        QPixmap pmp;
        qDebug()<<" image is value or not "<<image.isValid();
        // pmp.fromImage(image);
        //m_image.setPixmap(pmp);

    }
}

void Widget::changeImage(QMediaContent content)
{

}

void Widget::onMute()
{

    qDebug()<<"dianwo jinng yin "<< "  && player is mute "<<m_player->isMuted();
    if(m_player->isMuted())             // 判断当前的静音状态
    {
        m_player->setMuted(true);       // 设置静音
    }
    else
    {
        m_player->setMuted(false);       // 设置静音为false
    }


}

void Widget::setViewCurrentIndex(int index)
{
   //auto myModel =m_view.model();
   //m_view.setCurrentIndex(myModel[index]);
    m_view.selectRow(index);

}

void Widget::dragEnterEvent(QDragEnterEvent *e)
{
    if (e->mimeData()->hasUrls())          // ���������϶����ļ��д���rul
    {
        e->acceptProposedAction();          //���ñ��ζ���Ϊ����
    }
    else {
        e->ignore();                        //�������Ա����϶��ļ�
    }

}



void Widget::dropEvent(QDropEvent *e)
{
    if (e->mimeData()->hasUrls())          // ����ץȡ�������ļ���·��
    {
        auto list = e->mimeData()->urls();      //��ȡץȡ�ļ���list

        auto dropSize = list.size();            //��ȡ���ε�ץȡ���ļ�������
        auto playList = m_player->playlist();


        for (int i = 0; i < dropSize; ++i)
        {

            auto path = list[i].toLocalFile();     // ��ȡ·��
            qDebug() << "path name = " << path;       //������ǰ��·��
            if (!existFile("./data.txt", path))       // �жϵ�ǰ���ļ��Ƿ��Ѿ�����
            {
                playList->addMedia(QUrl(path));        // ����ǰ��·�����ӵ�playList
                writeFile("./data.txt", path);        // ��·��д��./data.txt ·��
            }
        }


        updateList("./data.txt");


        const int _ZERODOWN = -1;
        int sz = fileLocal("./data.txt", list[0].toLocalFile());
        if (sz == _ZERODOWN)
        {
            return;
        }
        playList->setCurrentIndex(sz);
        m_player->play();

        qDebug() << "sz = " << sz;


    }
    else
    {
        e->ignore();
    }

}

void Widget::closeEvent(QCloseEvent *event)
{
    // 判断播放状态是否是在播放中
    qDebug()<<"调用重写的closeEvent() >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
    if(m_player->state() == QMediaPlayer::PlayingState)
    {
        const QString str_tip="当前正在播放是否关闭！";
        QMessageBox * box = new QMessageBox;     //生成一个对话框
        box->setAttribute(Qt::WA_DeleteOnClose);    // 关闭是自动释放内存
        box->setIcon(QMessageBox::Warning);         // 对话框的标题
        box->setStandardButtons(QMessageBox::Ok|QMessageBox::Cancel); // 对话框的按钮
        box->setText(str_tip);                      // 询问式的文字
        m_player->pause();                          // 暂停播放

        if(box->exec() == QMessageBox::Ok)          // 获取按钮的值
        {
            event->accept();                        // 退出播放器
        }
        else
        {
            event->ignore();                        // 忽略本次关闭
            m_player->play();                       // 继续播放音乐
        }
    }
    else
    {
        event->accept();
    }

}

void Widget::keyPressEvent(QKeyEvent *event)
{

    qDebug()<<__func__<<event->key();
    if(event->key() == Qt::Key_Tab)
    {
        auto index = tabWidget->currentIndex();
        auto count= tabWidget->count();
        qDebug()<<"count "<<count;
    }
    else
    {
         QMainWindow::keyPressEvent( event);
    }

}


void Widget::initialStatusBar()
{

    //  QStatusBar* s_bar = statusBar();
    //  s_bar->setStyleSheet("height:15%;width:100%;background-color:blue;");

    //  s_bar->addWidget(nullptr);
}

std::vector<QString>  Widget::readList(QString fileName)
{
    QFile file(fileName);
    std::vector<QString>list;
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        qDebug() << " open file success ";
        QTextStream text(&file);

        while (!text.atEnd())
        {
            auto rf = text.readLine();
            qDebug() << " rf " << rf;
            list.push_back(rf);
        }
        file.close();
    }
    else {
        std::cout << " read file error " << std::endl;
    }

    return list;
}

void Widget::writeFile(QString fileName, QString path)
{
    QFile file(fileName);
    if (file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Append)) // ��append ��text ��fang��ʽ�����ļ�
    {
        QTextStream text(&file);
        text << path << "\n";
    }

    file.close();                   // �ر��ļ�

}

QString Widget::getBaseName(QString fil)
{
    QFileInfo info(fil);
    return info.baseName();

}

bool Widget::existFile(QString fileName, QString path)
{
    bool ret = false;

    QFile file(fileName);

    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream text(&file);
        while (!text.atEnd())
        {
            QString str = text.readLine();
            if (str == path)
            {
                ret = true;
                break;
            }
        }

        file.close();
    }

    return ret;
}

int Widget::fileLocal(QString fileName, QString path)
{
    int sz = -1;
    QFile file(fileName);

    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream text(&file);
        while (!text.atEnd())
        {
            QString str = text.readLine();
            sz++;
            if (str == path)
            {

                break;
            }
        }

        file.close();
    }

    return sz;
}

int Widget::containFile(QString fileName, QString name)
{
    int sz = -1;
    QFile file(fileName);

    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream text(&file);
        while (!text.atEnd())
        {
            QString str = text.readLine();
            sz++;
            if (str.contains(name))
            {

                break;
            }
        }

        file.close();
    }

    return sz;
}

void Widget::updateList(QString fileName)
{
    QFile file(fileName);
    auto ISmodel = static_cast<QStandardItemModel*>(m_view.model());

    auto list = m_player->currentMedia();
    if (m_player->isMetaDataAvailable())
    {
        auto author = m_player->metaData("Author").toString();
        auto title = m_player->metaData("Title").toString();
        auto Time_t = m_player->metaData("time").toString();
        qDebug() << "author = " << author << " , title = " << title << " , time = " << Time_t;
    }
    else
    {
        qDebug() << __LINE__ << false;
    }
    auto currentName = list.canonicalResource().url().fileName();
    qDebug() << "toLoacalFile"<<list.canonicalResource().url().toLocalFile();
    qDebug()<<"path "<<list.canonicalResource().url().path();
    qDebug() <<"fileName:"<< list.canonicalResource().url().fileName();
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        int index = 0;
        QTextStream text(&file);
        while (!text.atEnd())
        {
            QString str = text.readLine();
            QFileInfo info(str);
            auto isSize = info.size();
            qDebug() << "isSize = " << isSize;
            qDebug()<<"fileName:"<<info.fileName();
            QString tex = info.fileName();              // 因为需要切换widget 所以用文件的后缀名来判断
            if (str.contains(currentName))
            {


                //auto durationMes = m_player->duration();
                //qDebug() << "durationMes = " << QString::number(durationMes);
                //auto t_time = formatTime(durationMes);
                //tex.append(" - " + t_time);

            }

            QStandardItem *item = new QStandardItem(tex);

            ISmodel->setItem(index++, item);


        }

        file.close();
    }
}

void Widget::setConnect()
{
    connect(&m_dial, SIGNAL(valueChanged(int)), this, SLOT(onValChange(int)));
    connect(&m_bar, &QAbstractSlider::valueChanged, this, &Widget::setPosition);
    // connect(&m_bar,SIGNAL())
    connect(&m_pre, SIGNAL(clicked(bool)), this, SLOT(onPre()));
    connect(&m_pause, SIGNAL(clicked(bool)), this, SLOT(onPause()));
    connect(&m_next, SIGNAL(clicked(bool)), this, SLOT(onNext()));
    connect(&m_bar, SIGNAL(sliderReleased()), this, SLOT(onBarPositionChange(int)));
    connect(m_player.get(), SIGNAL(positionChanged(qint64)), this, SLOT(onPositionChange(qint64)));
    connect(m_player.get(), SIGNAL(currentMediaChanged(QMediaContent)), this, SLOT(onAutoNext()));
    connect(&m_view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setIndex(int)));
    connect(&m_search,SIGNAL(clicked(bool)),this,SLOT(searchM()));
    //connect(&m_search, SIGNAL(clicked(bool)), this, SLOT(openFileDialog()));
    //  con
    //connect(&m_search,SIGNAL(clicked(bool)),this,&Widget::openFileDialog);
    connect(&m_view,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(onDoubleClickTheContent(QModelIndex)));
    connect(m_player.get(),SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),this,SLOT(changeImage(QMediaPlayer::MediaStatus )));
    connect(&m_mute,SIGNAL(clicked(bool)),this,SLOT(onMute()));
}

void Widget::checkToDisplay()
{
    std::array<QString,3>arr={
        "mp3",
        "flac",
        "ape",

    };
    qDebug()<<__LINE__<<"checkToDisPlay()";

    auto list = m_player->currentMedia();
    if (m_player->isMetaDataAvailable())
    {
        auto author = m_player->metaData("Author").toString();
        auto title = m_player->metaData("Title").toString();
        auto Time_t = m_player->metaData("time").toString();
        qDebug() << "author = " << author << " , title = " << title << " , time = " << Time_t;
    }
    auto file=list.canonicalResource().url().fileName();
    qDebug()<<__func__<<" file: "<<file;
    if(file.contains(arr[0])|| file.contains(arr[1])||file.contains(arr[2]))
    {
        tabWidget->setCurrentIndex(0);
        qDebug()<<"切换到播放列表页面";

    }else
    {
        qDebug()<<"切换到视频输出页面";
        tabWidget->setCurrentIndex(1);
    }

    auto image=m_player->metaData("CoverArtImage");
    // m_image.setPicture(image.);
    qDebug()<<"image.isvalue"<<image.isValid();
}

void Widget::changeMnowTitle()
{
    qDebug()<<" line : "<<__LINE__<<"  func : "<<__func__;
    auto list = m_player->currentMedia();
    auto file=list.canonicalResource().url().fileName();
    m_nowTitle.setText(file);

}

XingcentPlayerUi::XingcentPlayerUi(QWidget *parent):QMainWindow(parent),
    m_dial(Qt::Horizontal, this), m_pre(this),
    m_pause(this), m_next(this), m_bar(Qt::Horizontal, this) // ����Ϊˮƽ������bar
  , m_player(new QMediaPlayer), m_search(this), m_text(this),
    m_videoPlay(this),
    m_time(this), m_view(this),m_image(this),m_nowTitle(this),
    m_lyr(this), m_mute(this)
{

    setMinimumSize(1386,726);
    initialLyr();

#define __XINGCENT_WIN32

#ifdef  __XINGCENT_WIN32
    //    playerWinLayout();

#endif

#ifdef _XINGCENTANDROID

    playerAndroidLayout();

#endif

    initialStutusBar();
    initialUi();

}



void XingcentPlayerUi::playerAndroidLayout()
{
    qDebug()<<"使用机器人的布局";

    QGridLayout *layout = new QGridLayout(this);
    layout->setSpacing(6);
    layout->setContentsMargins(3, 3, 3, 3);  //���ñ߾࣬����������

    layout->addWidget(&m_view, 0, 0, 7, 3); //
    layout->addWidget(&m_text, 8, 0, 1, 2);
    layout->addWidget(&m_search, 8, 2, 1, 1);


    layout->addWidget(&m_pre, 9, 0, 1, 1); //
    layout->addWidget(&m_pause, 9, 1, 1, 1);
    layout->addWidget(&m_next, 9, 2, 1, 1);
    m_time.setText("");
    layout->addWidget(&m_bar, 9, 3, 1, 4);
    layout->addWidget(&m_time, 9, 7, 1, 1);
    layout->addWidget(&m_dial, 9, 8, 1, 2);
    //    layout->setColumnStretch(0,);
    // layout->addWidget(&m_dial,9,8,1,2);

    // layout->addWidget(&m_volup,9,7,1,1);
    // layout->addWidget(&m_voldown,9,8,1,1);

    layout->addWidget(&m_videoPlay, 0, 3, 9, 7);

    setLayout(layout);

}

void XingcentPlayerUi::playerWinLayout()
{
    qDebug()<<"使用田字牌布局";
    auto main_layout = new QGridLayout();

    auto left_layout= new QHBoxLayout;
    left_layout->addWidget(&m_view);


    auto left_layout_g = new QGridLayout;
    left_layout_g->addLayout(left_layout,0,0,8,3);
    left_layout_g -> addWidget(&m_text,8,0,1,2);
    left_layout_g -> addWidget(&m_search,8,2,1,1);

    auto foot_layout= new QGridLayout;
    auto foot_layout_left = new QHBoxLayout;
    foot_layout_left -> addWidget(&m_pre);
    foot_layout_left->addWidget(&m_pause);
    foot_layout_left -> addWidget(&m_next);

    foot_layout ->addLayout(foot_layout_left,0,0,1,3);
    foot_layout -> addWidget(&m_bar,0,3,1,3);
    foot_layout -> addWidget(&m_time,0,7,1,1);
    foot_layout-> addWidget(&m_dial,0,8,1,1);

    main_layout -> addLayout(left_layout_g,0,0,8,3);
    main_layout -> addLayout(foot_layout,9,0,1,10);
    main_layout -> addWidget(&m_videoPlay,0,3,10,7);



    setLayout(main_layout);
}

void XingcentPlayerUi::initialStutusBar()
{
    auto s_bar = statusBar();   // 状态栏
    s_bar->setStyleSheet("height:60px;width:100%;background-color:dodgerblue;");
    QGridLayout * g_layout = new QGridLayout;
    QWidget *show = new QWidget();
    m_nowTitle.setParent(show);
    m_time.setParent(show);
    m_bar.setParent(show);
    g_layout->addWidget(&m_nowTitle,0,0,1,2);
    g_layout->addWidget(&m_time,0,2,1,1);
    g_layout->addWidget(&m_bar,1,0,1,3);
    show->setLayout(g_layout);
    m_pre.setStyleSheet("background-color:white;border-radius:20px;");
    m_pause.setStyleSheet("background-color:white;border-radius:20px;");
    m_next.setStyleSheet("background-color:white;border-radius:20px;");
    m_text.setStyleSheet("height:40px;width:300px;background-color:white;border-radius:8px;");
    m_image.setStyleSheet("height:60px;width:60px;background-color:gray;border-image:url(:img/music.png);");
    QFont font ;
    font.setBold(true);
    //font.setItalic(true);
    font.setPointSize(12);      // 设置字体尺寸
    font.setKerning(true);
    m_text.setFont(font);
    m_image.setFixedSize(60,60);
    m_mute.setText("点我静音");
    ;
    m_bar.setStyleSheet("height:13px;;color:greenyellow;");
    m_bar.setMinimumWidth(400);
    m_dial.setFixedSize(147,10);
    m_time.setText("00:00- 00:00");
    m_pre.setFixedSize(60,60);
    m_pause.setFixedSize(60,60);
    m_next.setFixedSize(60,60);


    s_bar   ->addWidget(&m_pre);
    s_bar -> addWidget(&m_pause);
    s_bar ->addWidget(&m_next);
    s_bar ->addWidget(&m_image);
    //    s_bar -> addWidget(&m_bar);
    //s_bar -> addWidget(&m_time);
    s_bar->addWidget(show);
    s_bar->addWidget(&m_mute);
    s_bar -> addWidget(&m_dial);
    s_bar->addWidget(&m_text);
    s_bar->addWidget(&m_search);


    //    s_bar->setVisible();
}

void XingcentPlayerUi::initialUi()
{
    qDebug()<<" initail UI ";
    tabWidget ->setTabPosition(QTabWidget::West);
    auto forLayout = new QWidget;

    // 如果代码有问题就是这里了
    QWidget * widget = new QWidget;
    m_view.setParent(widget);
    QGridLayout * g_layout = new QGridLayout;
    g_layout->addWidget(&m_view,0,0,8,3);
    g_layout->addWidget(&m_lyr,0,3,8,5);
    widget->setLayout(g_layout);

    tabWidget -> addTab(widget,"播放列表");
    tabWidget -> addTab(&m_videoPlay,"视频输出");

    QVBoxLayout * layout = new QVBoxLayout;
    layout->addWidget(tabWidget);
    forLayout->setLayout(layout);
    setCentralWidget(forLayout);


}

void XingcentPlayerUi::initialLyr()
{

   QFont font;
   font.setBold(true);
   font.setFamily("宋体");
   font.setPixelSize(16);
   m_lyr.setFont(font);
   m_lyr.setText("暂无歌词显示");
   m_lyr.setStyleSheet("textAlign:center;");
  // m_lyr.setTextFormat(Qt::AlignHCenter);

}



}  // namespace end
